#!/usr/bin/env python
# -*- coding: utf-8 -*-

import hashlib

def hashfile(openedFile, hasher, blocksize=65536):
    """ This function compute and return the hash of a file.
    It uses the hasher given in parameters to compute the result.
    A block size can be specified in order to avoid out of memory errors
    for big files.

    Note the given file must be opened.
    """
    
    try:
        buf = openedFile.read(blocksize)
        while len(buf) > 0:
            hasher.update(buf)
            buf = openedFile.read(blocksize)
        return hasher.digest()
    except:
        print "hashfile> An error occured !"
        raise

f = open(u"C:\\Users\\Shona\\dev\\src\\python\\GoogleDataApi\\GoogleDocSync\\Préps cours\\4èmes\\Classroom English.doc",'r')
hasher = hashlib.sha1()
print hashfile(f, hasher)
close(f)
